package ideamaps.action;

import ideamaps.domain.User;
import ideamaps.manager.UserManager;

import com.opensymphony.xwork2.Preparable;
import com.taillive.core.dao.support.Page;
import com.taillive.core.web.StrutsAction;

public class UserAction extends StrutsAction implements Preparable{
	
	private UserManager userManager;
	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}
	
	private Long id;
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	
	private Long ids[];
	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}
	
	private Page p;
	public Page getP() {
		return p;
	}
	
	
	private int page;
	public void setPage(int page) {
		this.page = page;
	}


	public String list(){
		p = userManager.getPage(page, 10);
		p.setUrl("list.jspa");
		p.addUrlParam("type", "member");
		return SUCCESS;
	}
	
	private User user;
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}

	public String create(){
		return SUCCESS;
	}
	public String save(){
		userManager.create(user);
		return SUCCESS;
	}
	public String edit(){
		//user = userManager.get(id);
		return SUCCESS;
	}
	public String update(){
		userManager.update(user);
		return SUCCESS;
	}
	public String delete(){
		userManager.delete(ids);
		return SUCCESS;
	}

	public void prepare() throws Exception {
		if(id!=null && id>0){
			user = userManager.get(id);
		}
	}
}
